package cn.kgc.tafang.service;
import cn.kgc.tafang.dao.Init;
import cn.kgc.tafang.entity.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Scanner;


public class PlayGameOpera extends Thread{
static Tower tower=new Tower();
static Map<String,Hero> heroMap= Init.heroMap;
static Collection<Hero> heros=heroMap.values();
static List<Tower> towers=Init.towerList;
static List<Moster> mosters=Init.mosterList;
static List<JinYinMoster> jingYInMosters=Init.jinYinMosterList;
static List<Boss> bosses=Init.bosses;
static Scanner sc=new Scanner(System.in);
public  void a(User user){
    for (int i = 0; i <3 ; i++) {
    System.out.println("防御塔信息为:");
    System.out.println("等级|\t攻击力|\t生命值|\t攻击距离");
    System.out.println(tower.getGrand() + "级\t|\t" + tower.getPower() + "\t|\t|" + tower.getHP() + "\t" + tower.getDistance() + "米");
    System.out.println("-----------------------------------------------------------------------------------------------------");
    System.out.println("英雄信息为:");
        System.out.println("攻击力为:" +user.getHero().getPowed() + "\t攻击距离为:" +user.getHero().getDistance());
        System.out.println("-----------------------------------------------------------------------------------------------------");
        for (Tower tower : towers) {
            for (Moster moster : mosters) {
                for (JinYinMoster jinYin:jingYInMosters) {
                    for (Boss boss:bosses) {
                        System.out.println("本关卡怪物的信息为:");
                        System.out.println("怪物名\t等级\t攻击力\t攻击距离\t生命值\t怪物个数");
                        Moster moster1=new Moster("普通怪",1,50,50,50,1);
                        System.out.println(moster1.getName() + "\t" + moster.getGrade() + "\t\t" + moster1.getPower()+ "\t\t" + moster.getDistance() + "\t\t\t" + moster1.getHP()+ "\t\t" + moster.getMosterNum());
                        if (jinYin.getHP() != 0) {
                            System.out.println(jinYin.getName() + "\t" + jinYin.getGrade() + "\t\t" + jinYin.getPower() + "\t\t" + jinYin.getDistance() + "\t\t\t" + jinYin.getHP() + "\t\t" + jinYin.getMosterNum());
                        }
                        if (boss.getHP() != 0) {
                            System.out.println(boss.getName() + "\t" + boss.getGrade() + "\t\t" + boss.getPower() + "\t\t" + boss.getDistance() + "\t\t\t" + boss.getHP() + "\t\t" + boss.getMosterNum());
                        }
                        System.out.println("-----------------------------------------------------------------------------------------------------");
                        moster.setHP(moster1.getHP() * moster.getMosterNum());
                        moster.setPower(moster1.getPower() * moster.getMosterNum());
                        jinYin.setHP(jinYin.getHP() * jinYin.getMosterNum());
                        jinYin.setPower(jinYin.getPower() * jinYin.getMosterNum());
                        moster.setHP(moster.getHP()+jinYin.getHP()+boss.getHP());
                        moster.setPower(moster.getPower()+jinYin.getPower()+boss.getPower());
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("                     * *                     ");
                        System.out.println("                    * * *                    ");
                        System.out.println("                   * * * *                   ");
                        System.out.println("                  * * * * *                  ");
                        System.out.println("                 * * * * * *                  ");
                        System.out.println("                 * * * * * *                  ");
                        System.out.println("                 * * * * * *           **        ");
                        System.out.println("              * * * * * * * * *       ****       ");
                        System.out.println("              * * * * * * * * *        **         ");
                        System.out.println("              * * * * * * * * *       *  *        ");
                        System.out.println("              敌军还有5秒到达战场");
                        try {
                            for (int j = 4; j > 0; j--) {
                                System.out.println("                      " + j);
                                Thread.sleep(1000);
                            }
                            System.out.println("全军出击");
                            System.out.println("        *    *    *    *    *     ");
                            System.out.println("       ***--***--***--***--***     ");
                            System.out.println("       * *  * *  * *  * *  * *   ");
                            System.out.println("敌军距离防御塔还剩500米");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            Scanner sc = new Scanner(System.in);
                            String choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            if (user.getHero().getDistance() >= 500) {
                                System.out.println("进入英雄攻击范围，开始攻击");
                                Thread.sleep(500);
                                moster.setHP(moster.getHP() - user.getHero().getPowed());
                            }
                            Thread.sleep(300);
                            System.out.println("敌军距离防御塔还剩400米");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            if (user.getHero().getDistance() >= 400) {
                                System.out.println("进入英雄攻击范围，开始攻击");
                                Thread.sleep(500);
                                moster.setHP(moster.getHP() - user.getHero().getPowed());
                            }
                            if (PanDuan(user,i)) {
                                next(i,user);
                                i++;
                                if (i==2){
                                    System.out.println("恭喜大神全部通关!请静待游戏更新!!!");
                                    return;
                                }
                                continue;
                            }
                            if (tower.getHP() <= 0) {
                                if (tower.getHP() <= 0) {
                                    if (TiXingDian(user)){
                                    }else {
                                        return;
                                    }
                                }
                            }
                            Thread.sleep(300);
                            System.out.println("敌军距离防御塔还剩300米");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            if (user.getHero().getJuLi() >= 300) {
                                System.out.println("进入英雄攻击范围，开始攻击");
                                Thread.sleep(500);
                                moster.setHP(moster.getHP() - user.getHero().getPowed());
                            }
                            if (PanDuan(user,i)) {
                                if (i==2){
                                    System.out.println("恭喜大神全部通关!请静待游戏更新!!!");
                                    return;
                                }
                                if (!next(i,user)){
                                    return;
                                }
                                continue;
                            }
                            if (tower.getHP() <= 0) {
                                if (tower.getHP() <= 0) {
                                    if (TiXingDian(user)){
                                    }else {
                                        return;
                                    }
                                }
                            }
                            Thread.sleep(300);
                            System.out.println("敌军距离防御塔还剩200米");
                            System.out.println("进入防御塔攻击范围，防御塔开始攻击");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            moster.setHP(moster.getHP() - tower.getPower());
                            Thread.sleep(500);
                            moster.setHP(moster.getHP() - tower.getPower());
                            if (user.getHero().getDistance() >= 200) {
                                System.out.println("进入英雄攻击范围，开始攻击");
                                Thread.sleep(500);
                                moster.setHP(moster.getHP() - user.getHero().getPowed());
                            }
                            if (PanDuan(user,i)) {
                                if (i==2){
                                    System.out.println("恭喜大神全部通关!请静待游戏更新!!!");
                                    return;
                                }
                                if (!next(i,user)){
                                    return;
                                }
                                continue;
                            }
                            TiXing();
                            if (tower.getHP() <= 0) {
                                if (tower.getHP() <= 0) {
                                    if (TiXingDian(user)){
                                    }else {
                                        return;
                                    }
                                }
                            }
                            Thread.sleep(300);
                            System.out.println("敌军距离防御塔还剩100米");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            System.out.println("进入防御塔攻击范围，防御塔开始攻击");
                            moster.setHP(moster.getHP() - tower.getPower());
                            Thread.sleep(500);
                            moster.setHP(moster.getHP() - tower.getPower());
                            if (user.getHero().getDistance() >= 100) {
                                System.out.println("进入英雄攻击范围，开始攻击");
                                Thread.sleep(500);
                                moster.setHP(moster.getHP() - user.getHero().getPowed());
                            }
                            if (jinYin.getDistance() >= 100) {
                                System.out.println("进入精英怪攻击范围");
                                tower.setHP(tower.getHP() - (moster.getPower()));
                                Thread.sleep(500);
                                tower.setHP(tower.getHP() - (moster.getPower()));
                            }
                            if (jinYin.getDistance() >= 100) {
                                tower.setHP(tower.getHP() - jinYin.getPower());
                                Thread.sleep(500);
                                tower.setHP(tower.getHP() - jinYin.getPower());
                            }
                            if (PanDuan(user,i)) {
                                if (i==2){
                                    System.out.println("恭喜大神全部通关!请静待游戏更新!!!");
                                    return;
                                }
                                if (!next(i,user)){
                                    return;
                                }
                                continue;
                            }
                            TiXing();
                            if (tower.getHP() <= 0) {
                                if (tower.getHP() <= 0) {
                                    if (TiXingDian(user)){
                                    }else {
                                        return;
                                    }
                                }
                            }
                            System.out.println("敌军距离防御塔还剩50米");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            moster.setHP(moster.getHP() - tower.getPower());
                            Thread.sleep(500);
                            moster.setHP(moster.getHP() - tower.getPower());
                            if (user.getHero().getDistance() >= 50) {
                                Thread.sleep(500);
                                moster.setHP(moster.getHP() - user.getHero().getPowed());
                            }
                            if (moster.getDistance() >= 50) {
                                tower.setHP(tower.getHP() - (moster.getPower() + jinYin.getPower()));
                                Thread.sleep(500);
                                tower.setHP(tower.getHP() - (moster.getPower() + jinYin.getPower()));
                            }
                            if (PanDuan(user,i)) {
                                if (i==2){
                                    System.out.println("恭喜大神全部通关!请静待游戏更新!!!");
                                    return;
                                }
                                if (!next(i,user)){
                                    return;
                                }
                                continue;
                            }
                            TiXing();
                            if (tower.getHP() <= 0) {
                                if (tower.getHP() <= 0) {
                                    if (TiXingDian(user)){
                                    }else {
                                        return;
                                    }
                                }
                            }
                            System.out.println("敌军已到达防御塔");
                            System.out.println("进入小兵攻击范围");
                            System.out.println("请选择是否使用技能 y.使用 n.不使用");
                            choice = sc.next();
                            if (choice.equals("y")) {
                                SkillOpera.Skill();
                            }
                            System.out.println("最终决战!!");
                            Thread.sleep(1000);
                            TiXing();
                            while (true) {
                                moster.setHP(moster.getHP() - tower.getPower() - user.getHero().getPowed());
                                tower.setHP(tower.getHP() - (moster.getPower() + jinYin.getPower()));
                                if (PanDuan(user,i)) {
                                    if (i==2){
                                        System.out.println("恭喜大神全部通关!请静待游戏更新!!!");
                                        return;
                                    }
                                    if (!next(i,user)){
                                        return;
                                    }
                                    continue;
                                }
                                if (tower.getHP() <= 0) {
                                    if (TiXingDian(user)){
                                    }else {
                                        return;
                                    }
                                }
                            }

                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}

        /**
         * 点卷提醒方法
         */
        public static boolean TiXingDian(User user){
            System.out.println("防御塔被破！");
            System.out.println("是否花费60点卷继续通过 y.是 n.否");
            String choice = sc.next();
            if (choice.equals("y")) {
                    if (user.getHero().getDianJuan()>60){
                        System.out.println("继续通过,防御塔血量回满!");
                        tower.setHP(500);
                        user.getHero().setDianJuan(user.getHero().getDianJuan()-60);
                        return true;
                    }else {
                        System.out.println("点卷不足,请充值后再来,通过失败!!");
                        return false;
                    }
                } else {
                System.out.println("通关失败,请升级装备后再来!!");
            }
            return false;
        }
        /**
         * 提醒方法
         */
        public static void TiXing() throws InterruptedException {
            for (Tower tower:towers) {
                if (tower.getHP() < 300) {
                    System.out.println("防御塔血量不足300");
                    System.out.println("                 *                   ");
                    System.out.println("                   -* *               **        ");
                    System.out.println("              *   *  - * -           ****       ");
                    System.out.println("              *  * * *  - * *         **         ");
                    System.out.println("              * *  -  * * * *        *  *        ");
                    System.out.println("是否选择使用技能 y是 n否");
                    String choice1 = sc.next();
                    if (choice1.equals("y")) {
                        SkillOpera.Skill();
                        if (tower.getHP() > 0) {
                            System.out.println("防御塔血量为:" + tower.getHP());
                        } else {
                            System.out.println("防御塔血量为0");
                        }
                    }
                }
            }
        }
        /**
         * 判断是否通过该关卡
         * @return
         */
        public static boolean PanDuan(User user,int i){
                for (Moster moster:mosters) {
                    for (JinYinMoster jinYin:jingYInMosters) {
                        for (Boss boss:bosses){
                        if (moster.getHP()+jinYin.getHP()+boss.getHP()<=0) {
                            try {
                                System.out.println("....");
                                Thread.sleep(1000);
                                System.out.println("....");
                                Thread.sleep(1000);
                                System.out.println("劈里啪啦,一顿乱战");
                                System.out.println("防御塔血量剩:" + tower.getHP());
                                System.out.println("怪物全死了");
                                System.out.println("恭喜通过第"+(i+1)+"个关卡");
                                System.out.println("奖励100金币");
                                user.getHero().setMongey(user.getHero().getMongey() + 100);
                                return true;
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }

                    }
                }
            }
            return false;
        }

        /**
         * 选择是否开启下一关
         */
        public static boolean next(int i,User user) {
                for (Moster moster : mosters) {
                    for (JinYinMoster jinYin : jingYInMosters) {
                        for (Boss boss : bosses) {
                            System.out.println("请选择是否进行下一关 y是 n否");
                            Scanner sc = new Scanner(System.in);
                            String choice = sc.next();
                            jinYin.setName("精英怪");
                            jinYin.setHP(200);
                            jinYin.setPower(100);
                            jinYin.setDistance(100);
                            jinYin.setGrade(10);
                            jinYin.setMosterNum(1);
                            moster.setMosterNum(8);
                            if (choice.equals("y")) {
                                if (i == 0) {
                                    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                    System.out.println("本关卡有精英怪现身，建议升级防御塔后再进行挑战!");
                                    System.out.println("请选择是否升级防御塔 y.是 n.否");
                                    choice = sc.next();
                                    if (choice.equals("y")) {
                                        if (user.getHero().getMongey() >= tower.getPrice()) {
                                            tower.setHP(tower.getHP() + 500);
                                            tower.setGrand(tower.getGrand() + 1);
                                            tower.setPower(tower.getPower() + 50);
                                            tower.setPrice(tower.getPrice() + 200);
                                            user.getHero().setMongey(user.getHero().getMongey() - tower.getPrice());
                                            System.out.println("升级成功");
                                            System.out.println("                                ");
                                            System.out.println("                                      ");
                                            System.out.println("                 *   *   *   *          ");
                                            System.out.println("              *       * *        *               ");
                                            System.out.println("           *         * * *         *              ");
                                            System.out.println("         *          * * * *          *             ");
                                            System.out.println("        *          * * * * *          *           ");
                                            System.out.println("       *          * * * * * *          *         ");
                                            System.out.println("       *          * * * * * *          *         ");
                                            System.out.println("       *          * * * * * *          *   **        ");
                                            System.out.println("        *      * * * * * * * * *      *   ****       ");
                                            System.out.println("         *     * * * * * * * * *     *     **         ");
                                            System.out.println("           *   * * * * * * * * *   *      *  *        ");
                                        } else {
                                            System.out.println("金币不足,无法升级!请充值后再来!!");
                                        }

                                    }
                                    System.out.println("开始挑战!!!");
                                } else if (i == 1) {
                                    boss.setHP(1000);
                                    boss.setPower(200);
                                    boss.setDistance(200);
                                    boss.setGrade(10);
                                    boss.setMosterNum(1);
                                    boss.setName("终极大Boss");
                                    jinYin.setHP(100);
                                    jinYin.setMosterNum(3);
                                    moster.setMosterNum(10);
                                    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!");
                                    System.out.println("大Boss即将来袭,请做好准备!");
                                    System.out.println("请选择是否升级防御塔 y.是 n.否");
                                    choice = sc.next();
                                    if (choice.equals("y")) {
                                        if (user.getHero().getMongey() >= tower.getPrice()) {
                                            tower.setHP(tower.getHP() + 2000);
                                            tower.setGrand(tower.getGrand() + 1);
                                            tower.setPower(tower.getPower() + 100);
                                            tower.setPrice(tower.getPrice() + 500);
                                            user.getHero().setMongey(user.getHero().getMongey() - tower.getPrice());

                                            System.out.println("升级成功");

                                        } else {
                                            System.out.println("金币不足,无法升级!请充值后再来!!");
                                        }
                                    }
                                    System.out.println("开始挑战!!!");
                                }
                                return true;
                            }else {
                                System.out.println("退出关卡!!");

                            }
                            }
                        }
                }
                return false;
            }
}
